package testJdk.commonUse.dateAndCalendar.testtimestamp;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @version 1.0.0
 * Created by cyd on 2022-01-05 16:45:13
 * @ClassName : learn_jdk.commonUse.date_and_calendar.testtimestamp.TestTimeStamp
 * @Description : 类描述
 */
public class TestTimeStamp {

    /**
     * Date转 timeStamp
     */
    @Test
    public void test01() throws ParseException {
        String time = "2022-03-15 00:00:00"; // timeStamp:1647187200000 1647273600000
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(time);
        System.out.println(date);
        // 结论：时间戳就是date.getTime()
        System.out.println(date.getTime());
    }

    /**
     * timeStamp转 Date
     */
    @Test
    public void test02() throws ParseException {
        long timeStamp = 1640576714000L;
        Date date = new Date(timeStamp);
        System.out.println(date);
    }
}
